class TalkTo extends Action {
	constructor(enity, target, callback) {
		super();
		
		this.enity = enity;
		this.target = target;
        this.callback = callback;
	}
	
	update() {
		// 检查与目标点距离
		const xDiff = this.target.x - this.enity.x;
		const yDiff = this.target.y - this.enity.y;
		const distance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
		
		// 如果小于2个格子则进行对话
		if(distance < this.enity.scene.gridSize * 2) {

			// 结束动作
			this.enity.action = null;
			this.enity.state = `idea`;
			
			// 执行NPC对话
			if(this.target.script) 
				this.target.script(this.target);

            // 结束动作
            this.callback(this);
		}
		else {
			
			// 更新移动逻辑
			new MoveTo(enity, enity.scene.findPath(enity.position, target.position)).update();
		}	
	}
}